<template>
	<view>
		<image @tap="previewImage" :src="avatar" :class="previewClass" :mode="mode" />
	</view>
</template>

<script>
const globalData = getApp().globalData;
export default {
	data() {
		return {};
	},
	/**
	 * 组件的属性列表
	 */
	props: {
		previewClass: {
			type: String
		},
		imageList: {
			type: Array,
			default: []
		},
		avatar: {
			type: String
		},
		mode: {
			type: String,
			default: 'aspectFill'
		}
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		checkAvatarUrl(url) {
			return url.indexOf('http') >= 0 || url.indexOf('https') >= 0;
		},
		previewImage() {
			let urls = [this.avatar];
			if (this.imageList.length != 0) {
				urls = this.imageList;
			}
			if (!this.checkAvatarUrl(this.avatar)) {
				return;
			}
			uni.previewImage({
				current: this.avatar,
				urls,
				complete: () => {
					globalData.isPreview = true;
				}
			});
		}
	},
	created: function () {}
};
</script>
<style></style>
